package com.liqi.display.controller;


import com.alibaba.fastjson.JSON;
import com.liqi.display.common.Results;
import com.liqi.display.common.SystemCode;
import com.liqi.display.utils.DateUtil;
import com.liqi.display.utils.HttpUtils;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * 评价信息表
 * 统计满意度汇总
 *今日满意度，本月满意度，本年满意度
 *
 * @author liqi
 * @since 2021-04-13
 */
@RestController
@RequestMapping("/weather")
public class WeatherController {

    private static Logger logger=LoggerFactory.getLogger(WeatherController.class);

    @RequestMapping("getWeather")
    public Results total(){
        Results results =new Results();
        try {
            Map<String, Object> map = new ConcurrentHashMap<>();
            String url = "http://api.map.baidu.com/weather/v1/";
            String params = "district_id=441500&data_type=all&ak=2LkzELeC08k2gPispAykYkumvVinK9Kn";
            String sendGetStr = HttpUtils.sendGet(url, params);
            if(!StringUtils.isEmpty(sendGetStr)) {
                results.setCode(SystemCode.SYS_OK.getKey());
                results.setMessage(SystemCode.SYS_OK.getValue());
                results.setData(JSON.parseObject(sendGetStr));
            }else {
                results.setCode(SystemCode.SYS_OK.getKey());
                results.setMessage(SystemCode.SYS_OK.getValue());
                results.setData(null);
            }
            return results;
        }catch (Exception e){
            logger.info("异常信息",e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }

    @GetMapping("/testJson")
    public void testJson() {
        System.out.println("json---------------");
        DateUtil.near30WorkDay();
    }

}
